﻿package displays.Sprites
{
	import debugs.Debug;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.filters.BlurFilter;
	import flash.filters.BitmapFilterQuality;
	import flash.text.TextFormat;
	import flash.filters.BitmapFilter
	import flash.text.TextFieldAutoSize;
	import flash.filters.GlowFilter;
	import gs.TweenMax;
	import gs.easing.*;
	import net.netvars;

	/**
	 * ...
	 * @author keys_star@163.com
	 */
	public class word extends Sprite
	{
		private var txt0:TextField;
		private var txt1:TextField;
		private var mShape:Shape;
		private var tween:TweenMax;
		public function word() 
		{
			init();
		}
		private function init():void {
			var bgColor = netvars.getVar("bgColor");
			var fColor = netvars.getVar("fColor");
			var size:uint = 40;
			txt0 = new TextField;
			txt0.selectable = false;
			txt0.autoSize = TextFieldAutoSize.LEFT;
			var tf:TextFormat = new TextFormat;
			tf.size = size;
			tf.color = bgColor;
			txt0.defaultTextFormat = tf;
			
			addChild(txt0);
			txt0.filters = [getGlowFilter()];
			
			
			txt1 = new TextField;
			txt1.selectable = false;
			txt1.autoSize = TextFieldAutoSize.LEFT;
			var tf0:TextFormat = new TextFormat;
			tf0.size = size;
			tf0.color = fColor;
			txt1.defaultTextFormat = tf0;
			addChild(txt1);
			txt1.filters = [getBlurFiter()];
		}
		public function set text(s:String):void {
			Debug.send(this + ".text: " + s);
			this.alpha = 1;
			txt0.text = s;
			txt1.text = s;
			setMask();
			//moveToId(3, 4);
		}
		private function getBlurFiter():BitmapFilter {
			var blurX:Number = 1;
            var blurY:Number = 1;
            return new BlurFilter(blurX, blurY, BitmapFilterQuality.LOW);
		}
		 private function getGlowFilter():BitmapFilter {
			 var bgColor = netvars.getVar("bgColor");
            var color:Number = bgColor;
            var alpha:Number = 1;
            var blurX:Number = 5;
            var blurY:Number = 5;
            var strength:Number = 11;
            var inner:Boolean = false;
            var knockout:Boolean = false;
            var quality:Number = BitmapFilterQuality.LOW;
            return new GlowFilter(color,
                                  alpha,
                                  blurX,
                                  blurY,
                                  strength,
                                  quality,
                                  inner,
                                  knockout);
        }
		private function setMask():void {
			var w:Number = txt0.width;
			var h:Number = txt0.width;
			mShape = new Shape;
			mShape.graphics.beginFill(0xFF00CC);
			mShape.graphics.drawRect(0, 0, 1, h);
			mShape.graphics.endFill();
			addChild(mShape);
			txt0.mask = mShape;
		}
		public function moveToId(d:uint, s:Number):void {
			var w:Number = (txt0.textWidth / Total) * d;
			var com:Function = null;
			if (d == Total) {
				Debug.send(this + ".com.id"+d+" .total: "+Total);
				com = wcom;
			}
			tween = new TweenMax(mShape, s, { width:w,ease:Linear.easeNone,onComplete:com } );
		}
		public function get Total():uint {
			return txt0.length;
		}
		private function wcom() {
			tween = new TweenMax(this, 0, {delay:5,alpha:0 } );
		}
	}
}